<template>
  <div style="width: 400px;">
    <el-descriptions
      title="订单信息"
      size="small"
      :column="2"
    >
      <el-descriptions-item label="学生">{{ data.useName }}</el-descriptions-item>
      <el-descriptions-item label="手机号">{{ data.phone }}</el-descriptions-item>
      <el-descriptions-item label="居住地">{{ data.province +data.city + data.district  }}</el-descriptions-item>
      <el-descriptions-item label="金额">
        <el-tag size="small">{{ data.courseFee }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="状态">
        {{ data.status }}
      </el-descriptions-item>
      <el-descriptions-item label="详细地址">{{ data.address }}</el-descriptions-item>
      <el-descriptions-item label="科目名称">{{ data.subject }}</el-descriptions-item>
      <el-descriptions-item label="授课频率">{{ data.frequency }}</el-descriptions-item>
      <el-descriptions-item label="备注">{{ data.remarks }}</el-descriptions-item>
    </el-descriptions>
    <div style="text-align:right" v-if="data.status==='未完成' && data.userId!==userId" >
      <el-button type="primary" size="mini" @click="handleView">确定</el-button>
    </div>
  </div>
</template>

<script>
import { getTutorrequest,updateTutorrequest } from '@/api/system/tutorrequest'
import {addOrders } from '@/api/system/orders';
import dayjs  from 'dayjs'
export default {
  props: {
    id: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      data: {},
      userId:this.$store.getters.id
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
  async  handleView(){
     let data = {
        ...this.data,
        status:"已完成"
     }
     await  updateTutorrequest(data)
     let order = {
        orderNumber:dayjs().format("ORDER_YYYYMMDDHHmmss"),
        tutorId:this.$store.getters.id,
        tutorName:this.$store.getters.name,
        tutorPhone:this.$store.getters.user.phonenumber || "未填写",
        requestId:data.id,
        userId:this.data.userId,
        userName:this.data.useName,
        userPhone:this.data.phone || "",
        status:"进行中",
        totalFee:this.data.courseFee,
        // startDate:this.data.startDate,
        // endDate:this.data.endDate,
        createdAt:dayjs().format("YYYY-MM-DD"),
        remarks:this.data.remarks,
     }
    await addOrders(order)
    this.$modal.msgSuccess('接单成功！')
    this.getData()
    },
    getData() {
      getTutorrequest(this.id).then((response) => {
        this.data = response.data
      })
    },
  },
}
</script>

<style scoped lang="scss">
</style>